﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace KgUtils.IO
{
    public static partial class DirectoryInfoExtension
    {
        /// <summary>
        /// Returns a file list from the current directory matching the searchPatterns.
        /// </summary>
        /// <param name="directory">The current directory.</param>
        /// <param name="searchPatterns">A list of search patterns. The rules are the same as <see cref="DirectoryInfo.GetFiles(string, SearchOption)"/>.</param>
        /// <param name="searchOption">Specifies whether the search operation should include only the current directory or should include all subdirectories.</param>
        /// <returns>An array of FileInfo that matches the search patterns.</returns>
        public static FileInfo[] GetFiles(this DirectoryInfo directory, List<string> searchPatterns, SearchOption searchOption)
        {
            Guard.AssertNotNull(searchPatterns, "searchPatterns");

            var result = searchPatterns.SelectMany(x => directory.GetFiles(x, searchOption));
            return result.ToArray();
        }
    }
}
